/*user相关的请求*/

import request from '@/utils/request'
import {
  areaSelectResponseData,
  UserResponseData,
} from '@/api/system/user/type'

/*枚举地址*/
enum API {
  /*获取全部用户信息*/
  USER_LIST_URL = '/system/user/list',
  USER_DEPT_TREE_URL = '/system/user/deptTree' /*获取部门下拉树*/,
  USER_AREA_TREE_URL = '/system/user/areaTree' /*获取所属地域下拉树树*/,
  USER_ADD_URL = '/system/user/add' /*添加用户信息*/,
  USER_EDIT_URL = '/system/user/edit' /*修改用户信息*/,
  USER_DELETE_URL = '/system/user/delete' /*删除用户信息*/,
  USER_CHANGE_STATUS_URL = '/system/user/changeStatus' /*修改角色状态*/,
  USER_UPDATE_PWS_URL = '/system/user/updateUserPwd' /*根据id修改用户密码*/,
  USER_RESET_PWS_URL = '/system/user/resetPwd' /*根据id来重置密码*/,
  USER_AUTH_ROLE_LIST_URL = '/system/user/authRole/list' /*查询授权角色*/,
  USER_AUTH_ROLE_ADD_URL = '/system/user/authRole/add' /*保留授权角色*/,
  USER_INFO_URL = '/system/user' /*根据userId获取用户信息*/,
}

/*分页查询用户信息*/
export const reqUserPageUrl = (queryParams: any) => {
  return request({
    url: API.USER_LIST_URL,
    method: 'get',
    params: queryParams,
  })
}

/*获取所有部门下拉树*/
export const reqDeptTreeSelect = () => {
  return request.get<any, any>(API.USER_DEPT_TREE_URL)
}

/*获取所有地域下拉树*/
export const reqAreaTreeSelect = () => {
  return request.get<any, areaSelectResponseData>(API.USER_AREA_TREE_URL)
}

// 查询部门下拉树结构
export const deptTreeSelect = () => {
  return request({
    url: '/system/user/deptTree',
    method: 'get'
  })
}


/*添加用户信息*/
export const reqUserAddUrl = (data: any) => {
  return request.post<any, any>(API.USER_ADD_URL, data)
}

/*修改用户信息*/
export const reqUserEditUrl = (data: any) => {
  return request.put<any, any>(API.USER_EDIT_URL, data)
}

/*删除用户信息*/
export const reqUserDeleteUrl = (data: any) => {
  return request.delete<any, any>(API.USER_DELETE_URL + '/' + data)
}

/*修改用户状态*/
export const reqUserChangeStatusUrl = (form: any) => {
  return request.put<any, any>(API.USER_CHANGE_STATUS_URL, form)
}

/*根据id修改用户密码*/
export const reqUpdateUserPwd = (form: any) => {
  return request.post<any, any>(API.USER_UPDATE_PWS_URL, form)
}

/*重置密码*/
export const reqResetPwd = (form: any) => {
  return request.post<any, any>(API.USER_RESET_PWS_URL, form)
}

// 查询授权角色
export function reqGetAuthRole(userId: any) {
  return request.get<any, any>(API.USER_AUTH_ROLE_LIST_URL + '/' + userId)
}

// 保存授权角色
export function reqUpdateAuthRoleUrl(data: any) {
  return request({
    url: API.USER_AUTH_ROLE_ADD_URL,
    method: 'put',
    params: data,
  })
}

/*根据userId获取用户信息*/
export function reqUserGetInfoByIdUrl(userId: any) {
  if (userId) {
    return request.get(API.USER_INFO_URL + '/' + userId)
  } else {
    return request.get(API.USER_INFO_URL + '/')
  }
}
